package appium1.common;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;

import java.io.File;
import java.net.URL;

public class BasicTestCase

{
    public static AppiumDriver driver;
    private Helper helper;
    public PageManager pageManager;

    @BeforeMethod
    public void setUp() throws Exception {
        File app = new File(System.getProperty("user.dir"), "Aut/osc.apk");
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("deviceName", "Android Emulator");
        capabilities.setCapability("platformVersion", "7.1.2");
        capabilities.setCapability("app", app.getAbsolutePath());
        capabilities.setCapability("noReset", "True"); //每次不重新安装app
        capabilities.setCapability("appPackage", "net.oschina.app");
        capabilities.setCapability("unicodeKeyboard", "True");
        capabilities.setCapability("resetKeyBoard", "True");
        capabilities.setCapability("appActivity", ".improve.main.splash.SplashActivity");
        driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
        helper = new Helper(driver);
        pageManager = new PageManager(helper);
        pageManager.getPageCommon().gotoMyTab();
        if ("ifabcasd156".equals(pageManager.getPagemysetings().getNickName())){
            pageManager.getPagemysetings().clickSettingBtn();
            pageManager.getPagesettings().clicklogout();
            pageManager.getPagesettings().clicblackbtn();
        }
        pageManager.getPageCommon().goToHomeTab();
    }

    @AfterMethod
    public void tearDown() {

    }
}
